import { post, setToken } from './index'

export default function (data) {
  return new Promise(async (res, rej) => {
    try {
      const resData = await post('/auth/login', data)
      if (resData.status === 200 && resData.data.msg === 'success') {
        setToken(resData.data.token)
        // TODO: resData.data.token
        res(true)
      } else {
        res(false)
      }
    } catch (error) {
      console.error(error)
      rej('ERROR：' + error.message)
    }
  })
}

